package com.depin.pdaapp.utils;

import android.content.Context;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.depin.pdaapp.R;
import com.xuexiang.xui.XUI;
import com.xuexiang.xui.utils.DensityUtils;
import com.xuexiang.xui.widget.popupwindow.popup.XUIPopup;

import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;

/**
 * Created by lzn.
 * Date：2020/5/28 14:04
 * Desc：
 **/
public class PopUtil {
    private Context mContext;

    public PopUtil(Context context) {
        mContext = context;
    }

    public void showPop(XUIPopup mNormalPopup, View view, String msg) {
        if (mNormalPopup == null) {
            mNormalPopup = new XUIPopup(mContext);
            TextView textView = new TextView(mContext);
            textView.setLayoutParams(mNormalPopup.generateLayoutParam(
                    DensityUtils.dp2px(mContext, 250),
                    WRAP_CONTENT
            ));
            textView.setLineSpacing(DensityUtils.dp2px(4), 1.0f);
            int padding = DensityUtils.dp2px(20);
            textView.setPadding(padding, padding, padding, padding);
            textView.setText(msg);
            textView.setTextColor(ContextCompat.getColor(mContext, R.color.xui_config_color_content_text));
            textView.setTypeface(XUI.getDefaultTypeface());
            mNormalPopup.setContentView(textView);
            mNormalPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                }
            });
        }
        mNormalPopup.setAnimStyle(XUIPopup.ANIM_GROW_FROM_CENTER);
        mNormalPopup.setPreferredDirection(XUIPopup.DIRECTION_BOTTOM);
        mNormalPopup.show(view);
    }
}
